/**
 * 
 */
package org.compiere.model;

import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Properties;
import java.util.logging.Level;

import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;

/**
 * @author A.Yerzhanov
 * 23.12.2012
 */
public class Mhrmtaxexempname extends X_hrm_taxexempname {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3556951050076870780L;
	
	/**	Static Logger	*/
	private static CLogger	s_log	= CLogger.getCLogger (Mhrmtaxexempname.class);

	/**
	 * @param ctx
	 */
	public Mhrmtaxexempname(Properties ctx) {
		super(ctx);
		// TODO Auto-generated constructor stub
	}
	
	/**
	 * @param ctx
	 * @param hrm_taxexempname_ID
	 * @param trxName
	 */
	public Mhrmtaxexempname(Properties ctx, int hrm_taxexempname_ID,
			String trxName) {
		super(ctx, hrm_taxexempname_ID, trxName);
		// TODO Auto-generated constructor stub
	}
	
	/**
	 * @param ctx
	 * @param rs
	 * @param trxName
	 */
	public Mhrmtaxexempname(Properties ctx, ResultSet rs, String trxName) {
		super(ctx, rs, trxName);
		// TODO Auto-generated constructor stub
	}

	/**  */
	public static int getNumber(Properties ctx){
		
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		int result = 0;
		
		// Employee data from the card
		String sql_ = "SELECT MAX(HRM_NUMBER) FROM HRM_TAXEXEMPNAME WHERE AD_CLIENT_ID=" + Env.getAD_Client_ID(ctx) + " ";
		try
		{
			pstmt = DB.prepareStatement(sql_,null);						
			rs = pstmt.executeQuery();
			if(rs.next())
				return rs.getInt(1);		
		}
		catch (SQLException e)
		{
			s_log.log(Level.SEVERE, "product", e);
		}
		finally
		{
			DB.close(rs, pstmt);
			rs = null; pstmt = null;
		}

		return result;
	}

	/* (non-Javadoc)
	 * @see org.compiere.model.PO#beforeSave(boolean)
	 */
	@Override
	protected boolean beforeSave(boolean newRecord) {
				
		if (newRecord){
			int number = Mhrmtaxexempname.getNumber(Env.getCtx());
			sethrm_number(number + 1);			
		}

		return super.beforeSave(newRecord);
	}

}
